package com.transitionseverywhere;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import com.transitionseverywhere.Transition;
import com.transitionseverywhere.utils.AnimatorUtils;
import com.transitionseverywhere.utils.PointFProperty;
import com.transitionseverywhere.utils.RectEvaluator;
import com.transitionseverywhere.utils.ViewGroupUtils;
import com.transitionseverywhere.utils.ViewOverlayUtils;
import com.transitionseverywhere.utils.ViewUtils;
import java.util.Map;

/* loaded from: classes.dex */
public class ChangeBounds extends Transition {
    private static final PointFProperty<View> BOTTOM_RIGHT_ONLY_PROPERTY;
    private static final PointFProperty<ViewBounds> BOTTOM_RIGHT_PROPERTY;
    private static final PointFProperty<Drawable> DRAWABLE_ORIGIN_PROPERTY;
    private static final String LOG_TAG = "ChangeBounds";
    private static final PointFProperty<View> POSITION_PROPERTY;
    private static final PointFProperty<View> TOP_LEFT_ONLY_PROPERTY;
    private static final PointFProperty<ViewBounds> TOP_LEFT_PROPERTY;
    private static RectEvaluator sRectEvaluator;
    boolean mReparent;
    boolean mResizeClip;
    int[] tempLocation;
    private static final String PROPNAME_BOUNDS = "android:changeBounds:bounds";
    private static final String PROPNAME_CLIP = "android:changeBounds:clip";
    private static final String PROPNAME_PARENT = "android:changeBounds:parent";
    private static final String PROPNAME_WINDOW_X = "android:changeBounds:windowX";
    private static final String PROPNAME_WINDOW_Y = "android:changeBounds:windowY";
    private static final String[] sTransitionProperties = {PROPNAME_BOUNDS, PROPNAME_CLIP, PROPNAME_PARENT, PROPNAME_WINDOW_X, PROPNAME_WINDOW_Y};

    static {
        if (Build.VERSION.SDK_INT >= 14) {
            DRAWABLE_ORIGIN_PROPERTY = new PointFProperty<Drawable>() { // from class: com.transitionseverywhere.ChangeBounds.1
                private Rect mBounds = new Rect();

                @Override // android.util.Property
                public void set(Drawable drawable, PointF pointF) {
                    drawable.copyBounds(this.mBounds);
                    this.mBounds.offsetTo(Math.round(pointF.x), Math.round(pointF.y));
                    drawable.setBounds(this.mBounds);
                }

                @Override // com.transitionseverywhere.utils.PointFProperty, android.util.Property
                public PointF get(Drawable drawable) {
                    drawable.copyBounds(this.mBounds);
                    return new PointF(this.mBounds.left, this.mBounds.top);
                }
            };
            TOP_LEFT_PROPERTY = new PointFProperty<ViewBounds>() { // from class: com.transitionseverywhere.ChangeBounds.2
                @Override // android.util.Property
                public void set(ViewBounds viewBounds, PointF pointF) {
                    viewBounds.setTopLeft(pointF);
                }
            };
            BOTTOM_RIGHT_PROPERTY = new PointFProperty<ViewBounds>() { // from class: com.transitionseverywhere.ChangeBounds.3
                @Override // android.util.Property
                public void set(ViewBounds viewBounds, PointF pointF) {
                    viewBounds.setBottomRight(pointF);
                }
            };
            BOTTOM_RIGHT_ONLY_PROPERTY = new PointFProperty<View>() { // from class: com.transitionseverywhere.ChangeBounds.4
                @Override // android.util.Property
                public void set(View view, PointF pointF) {
                    ViewUtils.setLeftTopRightBottom(view, view.getLeft(), view.getTop(), Math.round(pointF.x), Math.round(pointF.y));
                }
            };
            TOP_LEFT_ONLY_PROPERTY = new PointFProperty<View>() { // from class: com.transitionseverywhere.ChangeBounds.5
                @Override // android.util.Property
                public void set(View view, PointF pointF) {
                    ViewUtils.setLeftTopRightBottom(view, Math.round(pointF.x), Math.round(pointF.y), view.getRight(), view.getBottom());
                }
            };
            POSITION_PROPERTY = new PointFProperty<View>() { // from class: com.transitionseverywhere.ChangeBounds.6
                @Override // android.util.Property
                public void set(View view, PointF pointF) {
                    int round = Math.round(pointF.x);
                    int round2 = Math.round(pointF.y);
                    ViewUtils.setLeftTopRightBottom(view, round, round2, view.getWidth() + round, view.getHeight() + round2);
                }
            };
            return;
        }
        DRAWABLE_ORIGIN_PROPERTY = null;
        TOP_LEFT_PROPERTY = null;
        BOTTOM_RIGHT_PROPERTY = null;
        BOTTOM_RIGHT_ONLY_PROPERTY = null;
        TOP_LEFT_ONLY_PROPERTY = null;
        POSITION_PROPERTY = null;
    }

    public ChangeBounds() {
        this.tempLocation = new int[2];
        this.mResizeClip = false;
        this.mReparent = false;
    }

    public ChangeBounds(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.tempLocation = new int[2];
        this.mResizeClip = false;
        this.mReparent = false;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.ChangeBounds);
        boolean z = obtainStyledAttributes.getBoolean(R.styleable.ChangeBounds_resizeClip, false);
        obtainStyledAttributes.recycle();
        setResizeClip(z);
    }

    @Override // com.transitionseverywhere.Transition
    public String[] getTransitionProperties() {
        return sTransitionProperties;
    }

    public void setResizeClip(boolean z) {
        this.mResizeClip = z;
    }

    public boolean getResizeClip() {
        return this.mResizeClip;
    }

    public void setReparent(boolean z) {
        this.mReparent = z;
    }

    private void captureValues(TransitionValues transitionValues) {
        View view = transitionValues.view;
        if (!ViewUtils.isLaidOut(view, false) && view.getWidth() == 0 && view.getHeight() == 0) {
            return;
        }
        transitionValues.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
        transitionValues.values.put(PROPNAME_PARENT, transitionValues.view.getParent());
        if (this.mReparent) {
            transitionValues.view.getLocationInWindow(this.tempLocation);
            transitionValues.values.put(PROPNAME_WINDOW_X, Integer.valueOf(this.tempLocation[0]));
            transitionValues.values.put(PROPNAME_WINDOW_Y, Integer.valueOf(this.tempLocation[1]));
        }
        if (this.mResizeClip) {
            transitionValues.values.put(PROPNAME_CLIP, ViewUtils.getClipBounds(view));
        }
    }

    @Override // com.transitionseverywhere.Transition
    public void captureStartValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override // com.transitionseverywhere.Transition
    public void captureEndValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    private boolean parentMatches(View view, View view2) {
        if (this.mReparent) {
            TransitionValues matchedTransitionValues = getMatchedTransitionValues(view, true);
            if (matchedTransitionValues == null) {
                if (view == view2) {
                    return true;
                }
            } else if (view2 == matchedTransitionValues.view) {
                return true;
            }
            return false;
        }
        return true;
    }

    @Override // com.transitionseverywhere.Transition
    public Animator createAnimator(final ViewGroup viewGroup, TransitionValues transitionValues, TransitionValues transitionValues2) {
        int i;
        View view;
        boolean z;
        Animator ofPointF;
        int i2;
        int i3;
        int i4;
        int i5;
        Animator ofPointF2;
        int i6;
        View view2;
        ObjectAnimator objectAnimator;
        if (transitionValues == null || transitionValues2 == null) {
            return null;
        }
        if (sRectEvaluator == null) {
            sRectEvaluator = new RectEvaluator();
        }
        Map<String, Object> map = transitionValues.values;
        Map<String, Object> map2 = transitionValues2.values;
        ViewGroup viewGroup2 = (ViewGroup) map.get(PROPNAME_PARENT);
        ViewGroup viewGroup3 = (ViewGroup) map2.get(PROPNAME_PARENT);
        if (viewGroup2 == null || viewGroup3 == null) {
            return null;
        }
        final View view3 = transitionValues2.view;
        if (parentMatches(viewGroup2, viewGroup3)) {
            Rect rect = (Rect) transitionValues.values.get(PROPNAME_BOUNDS);
            Rect rect2 = (Rect) transitionValues2.values.get(PROPNAME_BOUNDS);
            int i7 = rect.left;
            int i8 = rect2.left;
            int i9 = rect.top;
            int i10 = rect2.top;
            int i11 = rect.right;
            int i12 = rect2.right;
            int i13 = rect.bottom;
            final int i14 = rect2.bottom;
            int i15 = i11 - i7;
            int i16 = i13 - i9;
            int i17 = i12 - i8;
            int i18 = i14 - i10;
            Rect rect3 = (Rect) transitionValues.values.get(PROPNAME_CLIP);
            final Rect rect4 = (Rect) transitionValues2.values.get(PROPNAME_CLIP);
            if ((i15 == 0 || i16 == 0) && (i17 == 0 || i18 == 0)) {
                i = 0;
            } else {
                i = (i7 == i8 && i9 == i10) ? 0 : 1;
                if (i11 != i12 || i13 != i14) {
                    i++;
                }
            }
            if ((rect3 != null && !rect3.equals(rect4)) || (rect3 == null && rect4 != null)) {
                i++;
            }
            if (i > 0) {
                if (!this.mResizeClip || (rect3 == null && rect4 == null)) {
                    ViewUtils.setLeftTopRightBottom(view3, i7, i9, i11, i13);
                    if (i != 2) {
                        view = view3;
                        z = true;
                        if (i7 != i8 || i9 != i10) {
                            ofPointF = AnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, getPathMotion(), i7, i9, i8, i10);
                        } else {
                            ofPointF = AnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, getPathMotion(), i11, i13, i12, i14);
                        }
                    } else if (i15 == i17 && i16 == i18) {
                        view = view3;
                        z = true;
                        ofPointF = AnimatorUtils.ofPointF(view3, POSITION_PROPERTY, getPathMotion(), i7, i9, i8, i10);
                    } else {
                        view = view3;
                        z = true;
                        ViewBounds viewBounds = new ViewBounds(view);
                        Animator ofPointF3 = AnimatorUtils.ofPointF(viewBounds, TOP_LEFT_PROPERTY, getPathMotion(), i7, i9, i8, i10);
                        Animator ofPointF4 = AnimatorUtils.ofPointF(viewBounds, BOTTOM_RIGHT_PROPERTY, getPathMotion(), i11, i13, i12, i14);
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.playTogether(ofPointF3, ofPointF4);
                        animatorSet.addListener(viewBounds);
                        ofPointF = animatorSet;
                    }
                } else {
                    ViewUtils.setLeftTopRightBottom(view3, i7, i9, Math.max(i15, i17) + i7, Math.max(i16, i18) + i9);
                    if (i7 == i8 && i9 == i10) {
                        i2 = i15;
                        i3 = i12;
                        i4 = i10;
                        i5 = i8;
                        ofPointF2 = null;
                    } else {
                        i2 = i15;
                        i3 = i12;
                        i4 = i10;
                        i5 = i8;
                        ofPointF2 = AnimatorUtils.ofPointF(view3, POSITION_PROPERTY, getPathMotion(), i7, i9, i8, i10);
                    }
                    if (rect3 == null) {
                        i6 = 0;
                        rect3 = new Rect(0, 0, i2, i16);
                    } else {
                        i6 = 0;
                    }
                    Rect rect5 = rect4 == null ? new Rect(i6, i6, i17, i18) : rect4;
                    if (rect3.equals(rect5)) {
                        view2 = view3;
                        objectAnimator = null;
                    } else {
                        ViewUtils.setClipBounds(view3, rect3);
                        Property<View, Rect> property = ChangeClipBounds.VIEW_CLIP_BOUNDS;
                        RectEvaluator rectEvaluator = sRectEvaluator;
                        Rect[] rectArr = new Rect[2];
                        rectArr[i6] = rect3;
                        rectArr[1] = rect5;
                        objectAnimator = ObjectAnimator.ofObject(view3, (Property<View, V>) property, (TypeEvaluator) rectEvaluator, (Object[]) rectArr);
                        final int i19 = i3;
                        final int i20 = i5;
                        final int i21 = i4;
                        view2 = view3;
                        objectAnimator.addListener(new AnimatorListenerAdapter() { // from class: com.transitionseverywhere.ChangeBounds.7
                            private boolean mIsCanceled;

                            @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                            public void onAnimationCancel(Animator animator) {
                                this.mIsCanceled = true;
                            }

                            @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                            public void onAnimationEnd(Animator animator) {
                                if (this.mIsCanceled) {
                                    return;
                                }
                                ViewUtils.setClipBounds(view3, rect4);
                                ViewUtils.setLeftTopRightBottom(view3, i20, i21, i19, i14);
                            }
                        });
                    }
                    ofPointF = TransitionUtils.mergeAnimators(ofPointF2, objectAnimator);
                    view = view2;
                    z = true;
                }
                if (view.getParent() instanceof ViewGroup) {
                    final ViewGroup viewGroup4 = (ViewGroup) view.getParent();
                    ViewGroupUtils.suppressLayout(viewGroup4, z);
                    addListener(new Transition.TransitionListenerAdapter() { // from class: com.transitionseverywhere.ChangeBounds.8
                        boolean mCanceled = false;

                        @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                        public void onTransitionCancel(Transition transition) {
                            ViewGroupUtils.suppressLayout(viewGroup4, false);
                            this.mCanceled = true;
                        }

                        @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                        public void onTransitionEnd(Transition transition) {
                            if (this.mCanceled) {
                                return;
                            }
                            ViewGroupUtils.suppressLayout(viewGroup4, false);
                        }

                        @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                        public void onTransitionPause(Transition transition) {
                            ViewGroupUtils.suppressLayout(viewGroup4, false);
                        }

                        @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                        public void onTransitionResume(Transition transition) {
                            ViewGroupUtils.suppressLayout(viewGroup4, true);
                        }
                    });
                }
                return ofPointF;
            }
            return null;
        }
        viewGroup.getLocationInWindow(this.tempLocation);
        int intValue = ((Integer) transitionValues.values.get(PROPNAME_WINDOW_X)).intValue() - this.tempLocation[0];
        int intValue2 = ((Integer) transitionValues.values.get(PROPNAME_WINDOW_Y)).intValue() - this.tempLocation[1];
        int intValue3 = ((Integer) transitionValues2.values.get(PROPNAME_WINDOW_X)).intValue() - this.tempLocation[0];
        int intValue4 = ((Integer) transitionValues2.values.get(PROPNAME_WINDOW_Y)).intValue() - this.tempLocation[1];
        if (intValue == intValue3 && intValue2 == intValue4) {
            return null;
        }
        int width = view3.getWidth();
        int height = view3.getHeight();
        Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        view3.draw(new Canvas(createBitmap));
        final BitmapDrawable bitmapDrawable = new BitmapDrawable(viewGroup.getContext().getResources(), createBitmap);
        bitmapDrawable.setBounds(intValue, intValue2, width + intValue, height + intValue2);
        Animator ofPointF5 = AnimatorUtils.ofPointF(bitmapDrawable, DRAWABLE_ORIGIN_PROPERTY, getPathMotion(), intValue, intValue2, intValue3, intValue4);
        if (ofPointF5 != null) {
            final float alpha = view3.getAlpha();
            view3.setAlpha(0.0f);
            ViewOverlayUtils.addOverlay(viewGroup, bitmapDrawable);
            ofPointF5.addListener(new AnimatorListenerAdapter() { // from class: com.transitionseverywhere.ChangeBounds.9
                @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                public void onAnimationEnd(Animator animator) {
                    ViewOverlayUtils.removeOverlay(viewGroup, bitmapDrawable);
                    view3.setAlpha(alpha);
                }
            });
        }
        return ofPointF5;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class ViewBounds extends AnimatorListenerAdapter {
        private int mBottom;
        private boolean mIsBottomRightSet;
        private boolean mIsTopLeftSet;
        private int mLeft;
        private int mRight;
        private int mTop;
        private View mView;

        public ViewBounds(View view) {
            this.mView = view;
        }

        public void setTopLeft(PointF pointF) {
            this.mLeft = Math.round(pointF.x);
            this.mTop = Math.round(pointF.y);
            this.mIsTopLeftSet = true;
            if (this.mIsBottomRightSet) {
                setLeftTopRightBottom();
            }
        }

        public void setBottomRight(PointF pointF) {
            this.mRight = Math.round(pointF.x);
            this.mBottom = Math.round(pointF.y);
            this.mIsBottomRightSet = true;
            if (this.mIsTopLeftSet) {
                setLeftTopRightBottom();
            }
        }

        private void setLeftTopRightBottom() {
            ViewUtils.setLeftTopRightBottom(this.mView, this.mLeft, this.mTop, this.mRight, this.mBottom);
            this.mIsTopLeftSet = false;
            this.mIsBottomRightSet = false;
        }
    }
}
